/*
 * Amos Kittelson 
 * COP3503 - Computer Science 2
 * Assignment 3 - Railroad Building
 * Due 6 July 2010 (Extended due to military duty)
 */

public class Edge implements Comparable<Edge> {
	private Vertex start;
	private Vertex end;
	private int cost;
	private int index;
	
	// Constructor
	Edge (Vertex s, Vertex e, int c){
		start = s;
		end = e;
		cost = c;
	}
	
	// Constructor
	Edge (Vertex s, Vertex e, int c, int id){
		start = s;
		end = e;
		cost = c;
		index = id;
	}
	
	// Constructor
	Edge (Edge t){
		start = t.start;
		end = t.end;
		cost = t.cost;
		index = t.index;
	}
			
	
	// The index number is assigned in order of Edges
	// read from the file
	public int getIndex(){
		return index;
	}
	
	// Return the edge weight
	public int getWeight(){
		return cost;
	}
	
	// Return the Vertex start label
	public Vertex getStart(){
		return start;
	}
	
	// Return the Vertex end label
	public Vertex getEnd(){
		return end;
	}
	
	// Sort the start and end labels alphabetically
	public void sort(){
		
		String a = start.getLabel();
		String b = end.getLabel();
		
		if (a.compareTo(b) > 0){
			start.setLabel(b);
			end.setLabel(a);
		}
	}
			
	public String toString(){
		// return "ID:" + index + " start:" + start + " end:" + end + " cost:" + cost;
		return start + " " + end + " " + cost;
	}

	// Compare by Edge weight
	public int compareTo(Edge t) {
		return cost - t.getWeight();
	}
	
	// Compare by Edge start label
	public int compareTo(Vertex v){
		String a = start.getLabel();
		String b = v.getLabel();
		
		return a.compareTo(b);
	}

	// Return Object pointer
	public Edge getObject(){
		return this;
	}
	
}
